@echo off
cls

set THIS_BAT_FILE=%0
set PATH_UTILITIES=%SOURCE_DIRECTORY%..\..\utilities
set PATH_SCRIPT=%PATH_UTILITIES%\mvs
set LOGGER=%PATH_UTILITIES%\cmdlog.exe

if not exist %LOGGER% set STDOUT_REDIRECTED=yes

if not "%STDOUT_REDIRECTED%" == "yes" (
    set STDOUT_REDIRECTED=yes
    cmd.exe /c %THIS_BAT_FILE% %* 2>&1 | %LOGGER% 1build.log
    exit/b
) 

echo -------------------------------------------------^> BEGIN WORK

for %%a in (.) do set NAME_PRODUCT=%%~na

set SOURCE_DIRECTORY=%~dp0
set GENERATOR=Visual Studio 11
set TOOLSET=v120_CTP_Nov2012
set MODE=RelWithDebInfo
set MODE=Release
set MODE=Debug
set ADDRESSMODEL=64
set ADDRESSMODEL=32
set ACTION=stop
set ACTION=launch
set ACTION=build
set UNITTESTMODE=ON
set UNITTESTMODE=OFF

echo -------------------------------------------------^> 1
SET DEB32=true
SET DEB64=true
SET REL32=false
SET REL64=false
SET RWD32=true
SET RWD64=true

call %PATH_SCRIPT%\clear.bat
if exist %SOURCE_DIRECTORY%..\..\external\%NAME_PRODUCT%   (rmdir /s /q %SOURCE_DIRECTORY%..\..\external\%NAME_PRODUCT% ) 

if "%DEB32%"   == "true" ( call :deb32 )
if "%DEB64%"   == "true" ( call :deb64 )
if "%REL32%"   == "true" ( call :rel32 )
if "%REL64%"   == "true" ( call :rel64 )
if "%RWD32%"   == "true" ( call :rwd32 )
if "%RWD64%"   == "true" ( call :rwd64 )
echo -------------------------------------------------^> 2

rem ===================================
:deb32
set MODE=Debug
set ADDRESSMODEL=32
call :make_target
exit /b

rem ===================================
:deb64
set MODE=Debug
set ADDRESSMODEL=64
call :make_target
exit /b

rem ===================================
:rel32
set MODE=Release
set ADDRESSMODEL=32
call :make_target
exit /b

rem ===================================
:rel64
set MODE=Release
set ADDRESSMODEL=64
call :make_target
exit /b

rem ===================================
:rwd32
set MODE=RelWithDebInfo
set ADDRESSMODEL=32
call :make_target
exit /b

rem ===================================
:rwd64
set MODE=RelWithDebInfo
set ADDRESSMODEL=64
call :make_target
exit /b


rem ----------------------------------------------------------------
:make_target

call %PATH_SCRIPT%\prepare.bat "%SOURCE_DIRECTORY%" "%GENERATOR%" "%TOOLSET%" "%MODE%" "%ADDRESSMODEL%" "%ACTION%"
call %PATH_SCRIPT%\make-mvs.bat
call %PATH_SCRIPT%\action.bat   
call %PATH_SCRIPT%\install_library.bat %SOURCE_DIRECTORY%..\..\external
exit /b

echo -------------------------------------------------^> END WORK
exit /b


